#!/bin/sh

[ -z "$1" ] && echo "Syntax: rbcc <file>" && exit 1
S="$1"
[ "`basename \"$S\" .Rc`" = "`basename \"$S\"`" ] || S="`basename "$S" .Rc`.R"

cat |  RCMD --file=- --slave --vanilla --args $S << EOF 
in.file <- commandArgs(trailingOnly=TRUE)
if(length(in.file) == 0) {
	stop("Syntax: rbcc <filename>")
} else  {
	try(dyn.load(.Internal(enableJIT(0))), silent=T)
	try(dyn.load("PATH/exportbc.so"), silent=T)
	if(is.loaded("exportbc")){
		source("PATH/bc.R") 
		cmpfile(in.file[[1]])
	} else stop("Unable to load compiler support ('PATH/exportbc.so')")
}
q("no") # why nothing exit
EOF
